﻿using Microsoft.AspNetCore.Authorization;
using StarsAdmin.Core.Consts;

namespace StarsAdmin.Core.JWT
{
    /// <summary>
    /// 配置角色授权策略
    /// </summary>
    public static class PolicyAuthorizationOptions
    {
        /// <summary>
        /// 添加角色授权策略
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public static AuthorizationOptions AddPolicyOptions(this AuthorizationOptions options)
        {
            //系统管理员
            options.AddPolicy(RoleTypeConst.SystemAdmin, policy => policy.RequireRole(RoleTypeConst.SuperAdmin, RoleTypeConst.SystemAdmin));
            //用户管理员
            options.AddPolicy(RoleTypeConst.UserAdmin, policy => policy.RequireRole(RoleTypeConst.SuperAdmin, RoleTypeConst.UserAdmin));
            //族库管理员
            options.AddPolicy(RoleTypeConst.FamilyLibraryAdmin, policy => policy.RequireRole(RoleTypeConst.SuperAdmin, RoleTypeConst.FamilyLibraryAdmin));
            //数据安全管理员
            options.AddPolicy(RoleTypeConst.DateSecurityAdmin, policy => policy.RequireRole(RoleTypeConst.SuperAdmin, RoleTypeConst.DateSecurityAdmin));
            return options;
        }
    }
}